package com.gyh.bootmybatis.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gyh.bootmybatis.dao.BookMapper;
import com.gyh.bootmybatis.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    BookMapper bookMapper;


    public PageInfo<Book> getPage(Integer pageNum,Book book) {
        PageHelper.startPage(pageNum,3,"id desc");
        List<Book> allBooks = bookMapper.findAllBooks(book);
        return new PageInfo<>(allBooks);
    }

    public void del(Integer[] ids) {
        bookMapper.deleteBooks(ids);
    }

    public Integer addBook(Book book) {
        return bookMapper.addBook(book);
    }

    public Book bookInfo(Integer id) {
        return bookMapper.findBookById(id);
    }

    public Integer update(Book book) {
       return bookMapper.updateBook(book);
    }
}
